package com.xxx.state;

/**
 * @version v1.0
 * @Description:
 * @Author zhanzhongxin
 * @Date 2021/7/30 15:14
 * @Copyright 博为峰
 */
public class WaitDemo {

    public static Object obj = new Object();

    public static void main(String[] args) {
        new Thread(new Runnable() {//Thread-0
            @Override
            public void run() {
                synchronized (obj) {
                    System.out.println(Thread.currentThread().getName() + "-A");
                    try {
                        obj.wait();//Thread-0 释放锁
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "-B");
                }
            }
        }).start();
        try {
            Thread.sleep(1000);//不释放锁
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        synchronized (obj) {
            System.out.println(Thread.currentThread().getName() + "-C");
            obj.notify();
        }
    }
}
